package com.hks360.car_treasure.factory;

import android.support.v4.app.Fragment;

import com.hks360.car_treasure.common.FragmentKey;
import com.hks360.car_treasure.fragment.MainFragment;
import com.hks360.car_treasure.fragment.control.ControlFragment;
import com.hks360.car_treasure.fragment.InfoDeviceFragment;
import com.hks360.car_treasure.fragment.InfoFragment;
import com.hks360.car_treasure.fragment.InfoUserFragment;
import com.hks360.car_treasure.fragment.LoginFragment;
import com.hks360.car_treasure.fragment.RegisterFragment;
import com.hks360.car_treasure.fragment.StrokeFragment;
import com.hks360.car_treasure.fragment.TrackFragment;
import com.hks360.car_treasure.fragment.control.ControlFragment_circle;

import java.util.HashMap;

/**
 * Created by rwq on 2016/3/14.
 */
public class FragmentFactory {
    private static HashMap<String,Fragment> hm = new HashMap<>();
    public static Fragment createFragment(String Tag){
        Fragment fragment = null;
        switch(Tag){
            case FragmentKey.LOGIN:
                if(hm.get(FragmentKey.LOGIN) == null){
                    fragment = new LoginFragment();
                    hm.put(FragmentKey.LOGIN,fragment);
                }
                else{
                    fragment = hm.get(FragmentKey.LOGIN);
                }
                break;
            case FragmentKey.REGISTER:
                if(hm.get(FragmentKey.REGISTER) == null){
                    fragment = new RegisterFragment();
                    hm.put(FragmentKey.REGISTER,fragment);
                }
                else{
                    fragment = hm.get(FragmentKey.REGISTER);
                }
                break;
            case FragmentKey.MAIN:
                if(hm.get(FragmentKey.MAIN) == null){
                    fragment = new MainFragment();
                    hm.put(FragmentKey.MAIN,fragment);
                }
                else{
                    fragment = hm.get(FragmentKey.MAIN);
                }
                break;
            case FragmentKey.TRACK:
                if(hm.get( FragmentKey.TRACK) == null){
                    fragment = new TrackFragment();
                    hm.put( FragmentKey.TRACK,fragment);
                }
                else{
                    fragment = hm.get( FragmentKey.TRACK);
                }
                break;
            case FragmentKey.CONTROL:
                if(hm.get(FragmentKey.CONTROL) == null){
                    fragment = new ControlFragment();
                    hm.put(FragmentKey.CONTROL,fragment);
                }
                else{
                    fragment = hm.get(FragmentKey.CONTROL);
                }
                break;
            case FragmentKey.STROKE:
                if(hm.get(FragmentKey.STROKE) == null){
                    fragment = new StrokeFragment();
                    hm.put(FragmentKey.STROKE,fragment);
                }
                else{
                    fragment = hm.get(FragmentKey.STROKE);
                }
                break;
            case FragmentKey.INFO:
                if(hm.get( FragmentKey.INFO) == null){
                    fragment = new InfoFragment();
                    hm.put( FragmentKey.INFO,fragment);
                }
                else{
                    fragment = hm.get( FragmentKey.INFO);
                }
                break;
            case FragmentKey.USER:
                if(hm.get(FragmentKey.USER) == null){
                    fragment = new InfoUserFragment();
                    hm.put(FragmentKey.USER,fragment);
                }
                else{
                    fragment = hm.get(FragmentKey.USER);
                }
                break;
            case FragmentKey.DEVICE_NAME:
                if(hm.get(FragmentKey.DEVICE_NAME) == null){
                    fragment = new InfoDeviceFragment();
                    hm.put(FragmentKey.DEVICE_NAME,fragment);
                }
                else{
                    fragment = hm.get(FragmentKey.DEVICE_NAME);
                }
                break;

        }
        return fragment;
    }
}
